package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
func main () {
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("请输入一个字符串: ")
	input, err := reader.ReadString('\n')
	if err != nil {
		fmt.Println("读取错误:", err)
		return
	}

	// 去除输入字符串末尾的换行符
	input = strings.TrimSuffix(input, "\n")

	// 在main函数中直接进行字符串压缩
	var compressed strings.Builder
	if len(input) > 0 {
		currentChar := input[0]
		count := 1

		for i := 1; i < len(input); i++ {
			if input[i] == currentChar {
				count++
			} else {
				compressed.WriteByte(currentChar)
				compressed.WriteString(strconv.Itoa(count))
				currentChar = input[i]
				count = 1
			}
		}

		// 添加最后一个字符及其计数
		compressed.WriteByte(currentChar)
		compressed.WriteString(strconv.Itoa(count))
	}

	// 输出压缩后的字符串
	fmt.Println("压缩后的字符串:", compressed.String())
}